#include "voice/widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setFixedSize(320,240);
    setWindowTitle("语音识别");
    ui->pushButton->setText("按下识别");

    /*创建音频对象 */
    audio = new Audio(this);

    qDebug() << "输出当前QT支持的openSSL版本: " << QSslSocket::sslLibraryBuildVersionString();
    qDebug() << "OpenSSL支持情况: " <<QSslSocket::supportsSsl();
    qDebug() << "OpenSSL运行时SSL库版本: " << QSslSocket::sslLibraryBuildVersionString();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_pressed()
{
    ui->pushButton->setText("松开识别");
    /* 开始录音 */
    audio->startAudio("audiofile");
}

void Widget::on_pushButton_released()
{
    ui->pushButton->setText("按下识别");
    /* 停止录音 */
    audio->stopAudio();

    /* 启动识别 */
    QString retStr = audio->startSpeech();
    my_speaker.say(retStr);//说话
    ui->lineEdit->setText(retStr);
}

void Widget::on_pushButton_clear_clicked()
{
    ui->lineEdit->clear();
}
